import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.junit.Test;

/*
 * Power by www.xiaoi.com
 */
/**
 * @author eko.zhan
 * @date Jan 8, 2015 3:39:07 PM
 * @version 1.0
 */
public class Tester {
	
	@Test
	public void testOracle(){
		Connection conn = DBManager.getOracleConnection();
		PreparedStatement ps = null;
		try {
			conn.setAutoCommit(false);
			ps = conn.prepareStatement("CREATE TABLE HOME (ID VARCHAR(32)  NOT NULL, TITLE VARCHAR(225))");
			ps.executeUpdate();
			ps = conn.prepareStatement("INSERT INTO HOME VALUES ('1', 'SHANGHAI')");
			ps.executeUpdate();
			ps = conn.prepareStatement("INSERT INTO HOME VALUES ('1', WUHAN)");
			ps.executeUpdate();
			//提交事务
			conn.commit();
		} catch (SQLException e) {
			e.printStackTrace();
			try {
				//操作不成功则回退  
				System.out.println("执行回退");
				conn.rollback();
			}catch(Exception ex){  
				ex.printStackTrace();
			}  
		} finally{
			DBManager.cleanup(conn, ps);
		}
	}
	
	@Test
	public void testSQLServer(){
		Connection conn = DBManager.getSQLServerConnection();
		PreparedStatement ps = null;
		try {
			conn.setAutoCommit(false);
			ps = conn.prepareStatement("CREATE TABLE HOME (ID VARCHAR(32)  NOT NULL, TITLE VARCHAR(225), CONSTRAINT [PK__HOME] PRIMARY KEY ([ID]))");
			ps.executeUpdate();
			ps = conn.prepareStatement("INSERT INTO HOME VALUES ('1', 'SHANGHAI')");
			ps.executeUpdate();
			ps = conn.prepareStatement("INSERT INTO HOME VALUES ('1', WUHAN)");
			ps.executeUpdate();
			//提交事务
			conn.commit();
		} catch (SQLException e) {
			e.printStackTrace();
			try {
				//操作不成功则回退  
				System.out.println("执行回退");
				conn.rollback();
			}catch(Exception ex){  
				ex.printStackTrace();
			}  
		} finally{
			DBManager.cleanup(conn, ps);
		}
	}
	
	@Test
	public void testConnect(){
		DBManager.getMySQLConnection();
		DBManager.getOracleConnection();
		DBManager.getSQLServerConnection();
	}
}
